package com.dependencies.springdatajpa.controller;

import com.dependencies.springdatajpa.entity.UserEntity;
import com.dependencies.springdatajpa.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhizhou   2024/7/30 23:26
 */
@RestController
@RequestMapping("/users")
public class UserController {
    
    private final UserService userService;
    
    public UserController(UserService userService) {
        this.userService = userService;
    }
    
    @GetMapping
    public List<UserEntity> getAllStudents() {
        return userService.getAllUsers();
    }
    
    @PostMapping
    public UserEntity saveStudent(@RequestBody UserEntity userEntity) {
        return userService.save(userEntity);
    }
    
    @DeleteMapping("/{id}")
    public void deleteStudent(@PathVariable Long id) {
        userService.delete(id);
    }
}
